﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="excercise-all.aspx.cs" Inherits="VQWEB.administrator.english.excercises.excercise_all" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
    <asp:ListView ID="lvExcercise" runat="server">
        <ItemTemplate>
            <p>
            Question: <%# Container.DataItemIndex + 1 %> 
            </p>
     
            <p class="excercise">
            <%# Eval("excercise_content")%>
            <input type="hidden" name="excercise_id" value='<%# Eval("excercise_id") %>' />  
            </p>
            
        </ItemTemplate>
    </asp:ListView>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/english/excercise/handler";
        $("#btnSave").live("click", function () {
            var list = new Array();
            var array_id = new Array();
            $("p.excercise").each(function () {
                var question = {};
                var input = $(this).find(":input");
                $.each(input, function () {
                    var type = $(this).attr("type");
                    var name = $(this).attr("name").trim().toLowerCase();
                    var value = $(this).val().trim().toLowerCase();

                    switch (type) {
                        case "hidden":
                            question[name] = value;
                            array_id.push(value);
                            break;
                        case "radio":
                            if ($(this).prop("checked") & value != "")
                                question[value] = value;
                            break;
                        case "checkbox":
                            if ($(this).prop("checked")) {
                                name = name.substring(name.indexOf("_") + 1);
                                question[name] = value;
                            }
                            break;
                        case "text":
                            name = name.substring(name.indexOf("_") + 1);
                            if (name != "")
                                question[name] = value;
                            break;
                    }
                });
                list.push(question);
            });

            $.post(url_ashx, { result: JSON.stringify(list), array_id: JSON.stringify(array_id) }, function (data) {
                alert(data);
            });
        });


        $("input[type='radio']").live("click", function (e) {
            var radioName = $(this).attr("name");           
            var radioText = e.currentTarget.nextSibling.data;
            var input = $("input[type='text'][name^=" + radioName + "]");
            input.val(radioText);
        });

    </script>
</asp:Content>
